list01 = [1,2,3,4]
for item in list01:
    print(item,end=" ")
print(" ")

iterator = list01.__iter__()
while True:
    try:
        item = iterator.__next__()
        print(item,end="  ")
    except StopIteration:
        break
            


class Vextor:
    def __init__(self,start,end):
        self.start = start
        self.end   = end
    def __iter__(self):
        return self
    def __next__(self):
        if self.start <= self.end:
            number = self.start
            self.start += 1
            return number
        else:
            raise StopIteration
v1 = Vextor(3,9)
for i in v1:
    print(i,end="  ")



list01 = [1,2,19,34,12]
def generaator(alist):
    for i in alist:
        if i & 2 == 0:
            yield i
g01 = generaator(list01)
for i in g01:
    print(i,end=" ")
print("  ")

class Vextor:
    def __init__(self,start,end):
        self.start = start
        self.end   = end
    def get_num(self):
        while True:
            if self.start > self.end:
                break
            num = self.start
            self.start += 1
            yield num 
v1 = Vextor(3,9)
for i in v1.get_num():
    print(i,end="")



list01 = [2,3,19,34,12]
g01 = ( i for i in list01 if i & 1 ==0)
for i in g01:
    print(i,end="  ")
print("")
list02 = list(g01)
print(list02)


def o1():
    print("OK")
def o2(p):
    p()
o2(o1)

def cond1(i):
    return i % 2 == 0
"未使用2函数"
def cond2(i):
    return i > 10
"未使用3函数"
def cond3(i):
    return i % 3 == 0
def list01(alist,cond):
    for i in alist:
        if cond(i):
            yield i
list02 = [12,22,43,55,9,33]
"可以在这里更改使用的函数 cond1()"
l1 = list01(list02,cond1)
for i in l1 :
    print(i)



f01 = lambda x:f"得到的值为{x}"
"""""
相当于这行代码
def f01(x):
    return f"返回值为{x}"
"""
print(f01(2))

def list01(alist,cond):
    for i in alist:
        if cond(i):
            yield i
list02 = [12,22,43,55,8,33]
l1 = list01(list02,lambda i:i%2==0)
for i in l1:
    print(i)



list01 = [1,2,3,4,5]
f1 = filter(lambda x:x%2 == 0 ,list01)
for i in f1:
    print(i,end=" ")
   


list01 = [1,2,3,4,5]
m1 = map(lambda x:x**2,list01)
print(list(m1))
print("")

list02 = [6,7,8]
m1 = map(lambda x,y:x**2 + y**2,list01,list02)
print(list(m1))



stu_dict =[
    {"name":"Nun","age":19},
    {"name":"Nu","age":18},
    {"name":"N","age":17},
]
list01 = sorted(stu_dict,key=lambda x:x["age"])
print(list01)
    


def fun01():
    print("fun01()函数")
def fun02():
    print("fun02()函数")
    return fun01
func = fun02()
func()
print("")

def fun01():
    print("fun01()函数")
    def fun02():
        print("fun02()函数")
    return fun02
func = fun02()
func()
print("")

def fun01(x):
    def fun02():
        return x+2
    return fun02
func = fun01(1)
print(func())
print("")



def fun02(func):
    def fun01():
        return func()+1
    return fun01
def func():
    print("func()函数")
    return 1
func = fun02(func)
print(func())
print("")

def fun02(func):
    def fun01():
        return func()+1
    return fun01
@fun02
def func():
    print("func()函数")
    return 1
print(func())
print("")

def fun02(func):
    def fun01(a,b):
        return func(a+1,b+1)
    return fun01
@fun02
def func(a,b):
    print("func()函数")
    return a**2+b**2
print(func(1,1))



def outer(arg):
    def fun02(func):
        def fun01(x):
            print(x)
            print("装饰器发挥作用")
            return func(x)**2
        return fun01
    return fun02
@outer("这是一个带参数的装饰器")
def func(x):
    print("调用func()函数")
    return x
print(func(2))
print(" ")

def outer(arg):
    def fun02(func):
        def fun01(x):
            print(x)
            print("装饰器发挥作用")
            return func(x)**2
        return fun01
    return fun02
def func(x):
    print("调用func()函数")
    return x 
func02 = outer("这是一个带参数的装饰器")
func = func02(func)
print(func(2))



username = "nun"
password = "123"
uesr_status = False
type = input("输入登录方式")
def login(login_type):
    def check(func):
        def wrapper (*args,**kwrags):
            global uesr_status
            if not uesr_status:
                if login_type == "社交账号" or login_type == "博客账号":
                    user = input("请输入账号：")
                    pwd =  input("请输入密码：")
                    if user == username and pwd == password:
                        uesr_status = True
                    else:
                        print("用户名或者密码有误")
                else:
                    print("登录方式无效")
            if uesr_status:
                return func(*args,**kwrags)
        return wrapper
    return check
@login(type)
def chat():
    print("聊天")
@login(type)
def shop():
    print("购物")
if __name__ == "__main__":
    chat()
    shop()




